package com.matrix.java.chap_05;

import java.util.Scanner;

public class Ex5_51 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the first string: ");
        String str1 = input.nextLine();
        System.out.print("Enter the second string: ");
        String str2 = input.nextLine();
        int maxNum = 0;
        if (!str1.substring(0, 1).equals(str2.substring(0, 1))) {
            System.out.println(str1 + " and " + str2 + " have no common prefix");
        } else {
            for (int i = 1; i < Math.min(str1.length(), str2.length()); i++) {
                if (str1.substring(i, i + 1).equals(str2.substring(i, i + 1))) {
                    maxNum = i + 1;
                }
            }
            System.out.println(str1.substring(0, maxNum));
        }
        input.close();
    }
}
